import org.bukkit.plugin.Plugin;
public class tpp_accept implements Listener {
    Plugin plugin = im.xz.cn.tpplayer1206.TpPlayer_1206.getPlugin(im.xz.cn.tpplayer1206.TpPlayer_1206.class);
    @EventHandler
    public void qwq(PlayerInteractEvent event) {
        Player player = event.getPlayer();
        String name = player.getName();
        Boolean permission = plugin.getConfig().getBoolean("permissionForAccept");
        try {
            if (permission) {
                try {
                    if (player.hasPermission("xzrui.tpplayer.action.accept")) {
                        boolean success = false;
                        try {
                            if (event.getPlayer().getInventory().getItemInMainHand().getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.translateAlternateColorCodes('&',plugin.getConfig().getString("itemName")))) {
                                String targetName = event.getPlayer().getInventory().getItemInMainHand().getItemMeta().getLore().get(2);
                                try {
                                    for (Object o : player.getServer().getOnlinePlayers().toArray()) {
                                        Player awa = (Player) o;
                                        if (awa.getName().toString().equalsIgnoreCase(targetName)) {
                                            Player targetPlayer = (Player) o;
                                            Location location = player.getLocation();
                                            targetPlayer.teleport(location);
                                            targetPlayer.sendMessage(ChatColor.translateAlternateColorCodes('&',plugin.getConfig().getString("successMessage")));
                                            int qwq = player.getInventory().getItemInMainHand().getAmount();
                                            player.getInventory().getItemInMainHand().setAmount(qwq - 1);
                                            event.setCancelled(true);
                                            success = true;
                                            break;
                                        }else {
                                        }
                                    }
                                }catch (NullPointerException ignore) {
                                }
                                try {
                                    if (!success) {
                                        player.sendMessage(ChatColor.RED + "此玩家不存在或已下线");
                                        int qwq = player.getInventory().getItemInMainHand().getAmount();
                                        player.getInventory().getItemInMainHand().setAmount(qwq - 1);
                                    }else {
                                        player.sendMessage(ChatColor.translateAlternateColorCodes('&',plugin.getConfig().getString("successMessage")));
                                    }
                                }catch (NullPointerException ignore) {
                                }
                            }

                        }catch (NullPointerException ignore) {
                        }
                    }else {
                        player.sendMessage(ChatColor.RED + " 权限不足！如果你确认这是不应该的，请联系管理员并让他检查你是否有xzrui.tpplayer.action.accept权限 ");
                    }
                }catch (NullPointerException ignore) {
                }
            }else {
                boolean success = false;
                try {
                    if (event.getPlayer().getInventory().getItemInMainHand().getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.translateAlternateColorCodes('&',plugin.getConfig().getString("itemName")))) {
                        String targetName = event.getPlayer().getInventory().getItemInMainHand().getItemMeta().getLore().get(2);
                        try {
                            for (Object o : player.getServer().getOnlinePlayers().toArray()) {
                                Player awa = (Player) o;
                                if (awa.getName().toString().equalsIgnoreCase(targetName)) {
                                    Player targetPlayer = (Player) o;
                                    Location location = player.getLocation();
                                    targetPlayer.teleport(location);
                                    targetPlayer.sendMessage(ChatColor.translateAlternateColorCodes('&',plugin.getConfig().getString("successMessage")));
                                    int qwq = player.getInventory().getItemInMainHand().getAmount();
                                    player.getInventory().getItemInMainHand().setAmount(qwq - 1);
                                    event.setCancelled(true);
                                    success = true;
                                    break;
                                }else {

                                }
                            }
                        }catch (NullPointerException ignore) {
                        }
                        try {
                            if (!success) {
                                player.sendMessage(ChatColor.RED + "此玩家不存在或已下线");
                                int qwq = player.getInventory().getItemInMainHand().getAmount();
                                player.getInventory().getItemInMainHand().setAmount(qwq - 1);
                            }else {
                                player.sendMessage(ChatColor.translateAlternateColorCodes('&',plugin.getConfig().getString("successMessage")));
                            }
                        }catch (NullPointerException ignore) {
                        }
                    }
                }catch (NullPointerException ignore) {
                }
            }
        }catch (NullPointerException ignore) {
        }
    }
}